package com.example.imtoken.modules.help_h5

import android.view.ViewGroup
import android.widget.LinearLayout
import com.example.imtoken.R
import com.example.imtoken.core.base.BaseActivity
import com.example.imtoken.databinding.ActivityHelpH5Binding
import com.just.agentweb.AgentWeb
import kotlinx.android.synthetic.main.include_head_help.view.*

class HelpH5Activity :
    BaseActivity<HelpH5ViewModel, ActivityHelpH5Binding>(HelpH5ViewModel::class.java) {

    private lateinit var mAgentWeb: AgentWeb

    private var title: String? = null
    private var url: String? = null

    override fun initLayoutId(): Int {
        return R.layout.activity_help_h5
    }

    override fun init() {
        title = intent.getStringExtra("title")
        url = intent.getStringExtra("url")
        if (title == null) finish()
        if (url == null) finish()

        dataBinding.headView.tvTitle.text = title
        dataBinding.headView.llClose.setOnClickListener { this.finish() }

        mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent(
                dataBinding.root as LinearLayout,
                1,
                LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT
                )
            )
            //设置进度条颜色与高度，-1为默认值，高度为2，单位为dp。
            .useDefaultIndicator(-1, 3)
            .createAgentWeb()
            .ready()
            .go(url)
    }

    override fun onPause() {
        mAgentWeb.webLifeCycle.onPause()
        super.onPause()
    }

    override fun onResume() {
        mAgentWeb.webLifeCycle.onResume()
        super.onResume()
    }

    override fun onDestroy() {
        mAgentWeb.webLifeCycle.onDestroy()
        super.onDestroy()
    }

}